package com.mbbb.yygh.hosp.controller;

import com.mbbb.yygh.common.result.R;
import com.mbbb.yygh.hosp.service.HospitalService;
import com.mbbb.yygh.model.hosp.Hospital;
import com.mbbb.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(description = "医院接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    //获取医院详情
    @ApiOperation(value = "获取医院详情")
    @GetMapping("show/{id}")
    public R show(@PathVariable String id) {

        //数据中又多种对象，建议使用Map
        Map<String, Object> hospital = hospitalService.showDetail(id);
        return R.ok().data("hospital",hospital);
    }

    //更新医院上线状态功能
    @ApiOperation(value = "更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public R lock(@PathVariable("id") String id,
                  @PathVariable("status") Integer status){
        hospitalService.updateHospStatus(id,status);
        return R.ok();
    }

    //医院列表（条件查询带分页）
    //HospitalQueryVo --> 查询条件
    @ApiOperation(value = "获取分页列表")
    @GetMapping("/getHospList/{page}/{limit}")
    public R getHospList(@PathVariable Integer page,
                         @PathVariable Integer limit,
                         HospitalQueryVo hospitalQueryVo) {
        //调用方法
        Page<Hospital> pages = hospitalService.selectHospPage(page,limit,hospitalQueryVo);
        return R.ok().data("pages",pages);
    }
}
